//+------------------------------------------------------------------------------------------------------------------+
#property description                                                                             "[XU-FOREX CHANGER]"
#define Version                                                                                   "[XU-FOREX CHANGER]"
//+------------------------------------------------------------------------------------------------------------------+
#property link        "https://forex-station.com/viewtopic.php?p=1294848283#p1294848283"
#property description "THIS IS A FREE INDICATOR"
#property description "                                                      "
#property description "Welcome to XARD UNIVERSE"
#property description "Let light shine out of darkness and illuminate your world"
#property description "and with this freedom leave behind your cave of denial"
#property indicator_chart_window
#property indicator_buffers 0
#property strict
string  ID;
extern string Indicator        = Version;
  extern bool showSymButtons   = true;  string aSymbols[];
//extern string Symbols          = "WS30;US500;NDX100;US2000;HK50;DAX30;USOUSD;GBPAUD;GBPJPY;GBPNZD;XAUUSD";
extern string Symbols          = "EURUSD;GBPUSD;AUDUSD;USDJPY;USDCHF;USDCAD;EURAUD;EURCAD;EURCHF;EURGBP;EURJPY;GBPJPY;GBPCHF;NZDUSD;AUDCAD;AUDJPY;CHFJPY;AUDNZD;NZDJPY;NZDCAD;NZDCHF;GBPNZD;EURNZD;GBPCAD;GBPAUD;AUDCHF;CADCHF;CADJPY";
input int     SymButtonsInARow = 1;             // Buttons in a horizontal row
input ENUM_BASE_CORNER SymCorner = 1;           // SymCorner
extern int    SymXshift     = 106;              // Horizontal shift of Symbol buttons
extern int    SymYshift     = 254;              // Vertical shift of Symbol buttons
input int     SymWidth      = 72;               // Width of Symbol buttons
input int     SymHeight     = 18;               // Height of Symbol buttons
input int     SymSize       = 10;               // Font size of Symbol
//+------------------------------------------------------------------------------------------------------------------+
extern bool showTFbuttons    = true;
input int     TimButtonsInARow = 1;             // Buttons in a horizontal row
input ENUM_BASE_CORNER TimCorner = 1;           // TimCorner
input int     TimXshift     = 33;               // Horizontal shift of Time buttons
extern int    TimYshift     = 214;              // Vertical shift of Time buttons
input int     TimWidth      = 26;               // Width of Time buttons
input int     TimHeight     = 18;               // Height of Time buttons
input int     TimSize       = 10;               // Font size of Time
input color   Bcolor        = C'35,35,35';      // Button color
input color   Dcolor        = clrDimGray;       // Button border color
input color   Tncolor       = clrSnow;          // Text color - normal
input color   Sncolor       = clrAqua;          // Text color - selected
extern bool   Transparent   = false;            // Transparent buttons?
//+------------------------------------------------------------------------------------------------------------------+
   int OnInit(){ID = "XU PANEL2";  
   Symbols = StringTrimLeft(StringTrimRight(Symbols));
   if(StringSubstr(Symbols,StringLen(Symbols)-1,1) != ";") Symbols = StringConcatenate(Symbols,";");
   int s=0,i=StringFind(Symbols,";",s); string current;
   while(i > 0){current = StringSubstr(Symbols,s,i-s);
      ArrayResize(aSymbols,ArraySize(aSymbols)+1);  aSymbols[ArraySize(aSymbols)-1] = current;
      s = i + 1; i = StringFind(Symbols,";",s);}  return(0);}
//+------------------------------------------------------------------------------------------------------------------+
   void OnDeinit(const int reason){switch(reason){
      case REASON_CHARTCHANGE :
      case REASON_RECOMPILE   :
      case REASON_CLOSE       : break;
      default : {
   string lookFor = ID+":";  int lookForLength = StringLen(lookFor);
   for(int i=ObjectsTotal()-1; i>=0; i--){string objectName = ObjectName(i);
   if (StringSubstr(objectName,0,lookForLength) == lookFor) ObjectDelete(objectName);}}}}
//+------------------------------------------------------------------------------------------------------------------+
   void createButton1(string name,string caption,int xpos,int ypos){
   if(ObjectFind(name)!=0)
    ObjectCreate(name,OBJ_BUTTON,0,0,0);
       ObjectSet(name,OBJPROP_CORNER   ,SymCorner);
       ObjectSet(name,OBJPROP_XDISTANCE,xpos);
       ObjectSet(name,OBJPROP_YDISTANCE,ypos);
       ObjectSet(name,OBJPROP_XSIZE,SymWidth);
       ObjectSet(name,OBJPROP_YSIZE,SymHeight);
   ObjectSetText(name,caption,SymSize,"Arial",Tncolor);
       ObjectSet(name,OBJPROP_FONTSIZE,SymSize);
       ObjectSet(name,OBJPROP_BORDER_TYPE,BORDER_FLAT);
       ObjectSet(name,OBJPROP_COLOR,Tncolor);
       ObjectSet(name,OBJPROP_BGCOLOR,Bcolor);
       ObjectSet(name,OBJPROP_BACK,Transparent);
       ObjectSet(name,OBJPROP_BORDER_COLOR,Dcolor);
       ObjectSet(name,OBJPROP_STATE,false);
       ObjectSet(name,OBJPROP_HIDDEN,true);}
//+------------------------------------------------------------------------------------------------------------------+
   void createButton2(string name,string caption,int xpos,int ypos){
   if(ObjectFind(name)!=0)
    ObjectCreate(name,OBJ_BUTTON,0,0,0);
       ObjectSet(name,OBJPROP_CORNER   ,TimCorner);
       ObjectSet(name,OBJPROP_XDISTANCE,xpos);
       ObjectSet(name,OBJPROP_YDISTANCE,ypos);
       ObjectSet(name,OBJPROP_XSIZE,TimWidth);
       ObjectSet(name,OBJPROP_YSIZE,TimHeight);
   ObjectSetText(name,caption,TimSize,"Arial",Tncolor);
       ObjectSet(name,OBJPROP_FONTSIZE,TimSize);
       ObjectSet(name,OBJPROP_BORDER_TYPE,BORDER_FLAT);
       ObjectSet(name,OBJPROP_COLOR,Tncolor);
       ObjectSet(name,OBJPROP_BGCOLOR,Bcolor);
       ObjectSet(name,OBJPROP_BACK,Transparent);
       ObjectSet(name,OBJPROP_BORDER_COLOR,Dcolor);
       ObjectSet(name,OBJPROP_STATE,false);
       ObjectSet(name,OBJPROP_HIDDEN,true);}
//+------------------------------------------------------------------------------------------------------------------+
   void setSymbolButtonColor(){string lookFor=ID+":symbol:";  int lookForLength=StringLen(lookFor);
   for(int i=ObjectsTotal()-1; i>=0; i--){string objectName = ObjectName(i);
   if(StringSubstr(objectName,0,lookForLength) == lookFor){string symbol = ObjectGetString(0,objectName,OBJPROP_TEXT);
   if(symbol != _Symbol)  ObjectSet(objectName,OBJPROP_COLOR,Tncolor);
                    else  ObjectSet(objectName,OBJPROP_COLOR,Sncolor);}}}
//+------------------------------------------------------------------------------------------------------------------+
   void setTimeFrameButtonColor(){string lookFor=ID+":time:"; int lookForLength=StringLen(lookFor);
   for (int i=ObjectsTotal()-1; i>=0; i--){string objectName = ObjectName(i);
   if(StringSubstr(objectName,0,lookForLength) == lookFor){
   int time = stringToTimeFrame(ObjectGetString(0,objectName,OBJPROP_TEXT));
   if(time != _Period)    ObjectSet(objectName,OBJPROP_COLOR,Tncolor);
                    else  ObjectSet(objectName,OBJPROP_COLOR,Sncolor);}}}
//+------------------------------------------------------------------------------------------------------------------+
   string sTfTable[] = {"M1","M5","15","30","H1","H4","D1","W1","MN"};
   int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};
//+------------------------------------------------------------------------------------------------------------------+
   string timeFrameToString(int tf){for (int i=ArraySize(iTfTable)-1; i>=0; i--)
   if(tf==iTfTable[i]) return(sTfTable[i]);  return("");}
//+------------------------------------------------------------------------------------------------------------------+
   int stringToTimeFrame(string tf){for (int i=ArraySize(sTfTable)-1; i>=0; i--)
   if(tf==sTfTable[i]) return(iTfTable[i]);  return(0);}
//+------------------------------------------------------------------------------------------------------------------+
   void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam){
   if (id==CHARTEVENT_OBJECT_CLICK && ObjectGet(sparam,OBJPROP_TYPE)==OBJ_BUTTON){
   if(StringFind(sparam,ID+":symbol:",0)==0) ChartSetSymbolPeriod(0,ObjectGetString(0,sparam,OBJPROP_TEXT),_Period);
   if(StringFind(sparam,ID+":time:"  ,0)==0) ChartSetSymbolPeriod(0,_Symbol,
   stringToTimeFrame(ObjectGetString(0,sparam,OBJPROP_TEXT)));
   if(StringFind(sparam,ID+":back:"  ,0)==0) ObjectSet(sparam,OBJPROP_STATE,false);}}// OnInit();}}
//+------------------------------------------------------------------------------------------------------------------+
   int start(){int xpos=0,ypos=0,maxx=0,maxy=0;
   if(showSymButtons){for(int i = 0; i<ArraySize(aSymbols); i++){
   if(i>0 && MathMod(i,SymButtonsInARow)==0){xpos=0; ypos+=SymHeight+1;}
   createButton1(ID+":symbol:"+string(i),aSymbols[i],SymXshift+xpos,SymYshift+ypos); xpos +=SymWidth+1;}}
   
   if(showTFbuttons){xpos = 0; ypos = 40;  for(int i = 0; i<ArraySize(sTfTable); i++){
   if(i>0 && MathMod(i,TimButtonsInARow)==0){xpos=0; ypos+=TimHeight+1;}
   createButton2(ID+":time:"+string(i),sTfTable[i],TimXshift+xpos,TimYshift+ypos); xpos+=TimWidth+1;}}
   setSymbolButtonColor();  setTimeFrameButtonColor(); return(0);}//EOF
//+------------------------------------------------------------------------------------------------------------------+
   void iPanel(string tls3,int x,int y,string Text,int fontSize,string Font,color Color){
         ObjectCreate(tls3,OBJ_LABEL,0,0,0);
            ObjectSet(tls3,OBJPROP_CORNER,0);
            ObjectSet(tls3,OBJPROP_XDISTANCE,x);
            ObjectSet(tls3,OBJPROP_YDISTANCE,y);
            ObjectSet(tls3,OBJPROP_BACK,false);
        ObjectSetText(tls3,Text,fontSize,Font,Color);}
//+------------------------------------------------------------------------------------------------------------------+